package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QMenu2;
import com.ruoyi.system.service.IQMenu2Service;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 二级目录Controller
 * 
 * @author ruoyi
 * @date 2024-06-19
 */
@Controller
@RequestMapping("/system/menu2")
public class QMenu2Controller extends BaseController
{
    private String prefix = "system/menu2";

    @Autowired
    private IQMenu2Service qMenu2Service;

    //@RequiresPermissions("system:menu2:view")
    @GetMapping()
    public String menu2()
    {
        return prefix + "/menu2";
    }

    /**
     * 查询二级目录列表
     */
    @CrossOrigin
    @PostMapping("/list/{q2Id}")
    @ResponseBody
    public TableDataInfo list(@PathVariable("q2Id") Long q2Id, QMenu2 qMenu2)
    {
        qMenu2.setQ2ParentId(q2Id);
        startPage();
        List<QMenu2> list = qMenu2Service.selectQMenu2List(qMenu2);

            return getDataTable(list, 1);


    }

    /**
     * 查询二级目录列表
     */
    @CrossOrigin
    @PostMapping("/list1")
    @ResponseBody
    public TableDataInfo list1( QMenu2 qMenu2)
    {

        startPage();
        List<QMenu2> list = qMenu2Service.selectQMenu2List(qMenu2);
        return getDataTable(list);


    }

    /**
     * 导出二级目录列表
     */
    @CrossOrigin
    //@RequiresPermissions("system:menu2:export")
    @Log(title = "二级目录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QMenu2 qMenu2)
    {
        List<QMenu2> list = qMenu2Service.selectQMenu2List(qMenu2);
        ExcelUtil<QMenu2> util = new ExcelUtil<QMenu2>(QMenu2.class);
        return util.exportExcel(list, "二级目录数据");
    }

    /**
     * 新增二级目录
     */
    @CrossOrigin
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存二级目录
     */
    @CrossOrigin
    @RequiresPermissions("system:menu2:add")
    @Log(title = "二级目录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QMenu2 qMenu2)
    {
        return toAjax(qMenu2Service.insertQMenu2(qMenu2));
    }

    /**
     * 修改二级目录
     */
    @CrossOrigin
    @RequiresPermissions("system:menu2:edit")
    @GetMapping("/edit/{q2Id}")
    public String edit(@PathVariable("q2Id") Long q2Id, ModelMap mmap)
    {
        QMenu2 qMenu2 = qMenu2Service.selectQMenu2ByQ2Id(q2Id);
        mmap.put("qMenu2", qMenu2);
        return prefix + "/edit";
    }

    /**
     * 修改保存二级目录
     */
    @CrossOrigin
    @RequiresPermissions("system:menu2:edit")
    @Log(title = "二级目录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QMenu2 qMenu2)
    {
        return toAjax(qMenu2Service.updateQMenu2(qMenu2));
    }

    /**
     * 删除二级目录
     */
    @CrossOrigin
    @RequiresPermissions("system:menu2:remove")
    @Log(title = "二级目录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qMenu2Service.deleteQMenu2ByQ2Ids(ids));
    }
}
